package com.group.auth;

import javax.swing.*;
import java.awt.*;

/**
 * @author lenovo
 */
public class RegisterFrame extends JFrame {
    public RegisterFrame() {
        setTitle("注册");
        setSize(300, 200);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);

        JTextField usernameField = new JTextField();
        JPasswordField passwordField = new JPasswordField();
        JLabel status = new JLabel();
        JButton registerBtn = new JButton("注册");

        setLayout(new GridLayout(4, 1));
        add(new JLabel("用户名：")); add(usernameField);
        add(new JLabel("密码：")); add(passwordField);
        add(registerBtn); add(status);

        registerBtn.addActionListener(e -> {
            String user = usernameField.getText().trim();
            String pass = new String(passwordField.getPassword()).trim();
            if (AuthManager.register(user, pass)) {
                status.setText("注册成功！");
            } else {
                status.setText("用户名已存在！");
            }
        });
    }
}
